﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using dto;
using util;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using common;
namespace dao
{
    public class AuditLogDAO
    {
        /* Author : Jenny
         * Date : 3/4/2012
         * function getAuditLogByCondition
         * parameter username, fromDate, endDate, actions, status
         * get all audit log data by the username, fromDate and endDate
         * return DataTable
         */ 
        public DataTable getAuditLogByCondition(String username, String fromDate, String endDate, String actions, String status)
        {
            DataTable dt = new DataTable();
            try
            {
                DataUtil.connect();
                String cmdText = "sp_getAuditLogByCondition";
                MySqlParameter[] arrParam = new MySqlParameter[6];
                arrParam[0] = new MySqlParameter("_UserName", username);
                arrParam[1] = new MySqlParameter("_FromDate", fromDate);
                arrParam[2] = new MySqlParameter("_EndDate", endDate);
                arrParam[3] = new MySqlParameter("_Actions", actions);
                arrParam[4] = new MySqlParameter("_Status", status);
                arrParam[5] = new MySqlParameter("_LanguageID", "1");
                dt = DataUtil.executeStore(cmdText, arrParam);

            }
            catch (Exception ex)
            {
                return null;
            }
            DataUtil.disconnect();
            return dt;
        }
        /* Author Jenny
         * Date : 3/4/2012
         * function sortDate
         * return String
         */
        public String sortDate(String date)
        {
            String[] arr = date.Split(new char[] {'/'});
            return arr[2] + "/" + arr[0] + "/" + arr[1];
        }
        /* Author Jenny
         * Date : 10/4/2012
         * function getAllActionsDetailsByEnglishID
         * get all actions such as Insert, update...
         * return DataTable
         * now only use english
         */
        public DataTable getAllActionsDetailsByEnglishID(String id)
        {
            DataTable dt = new DataTable();
            try
            {
                DataUtil.connect();
                String cmdText = "sp_getAllActionsDetailsByEnglishID";
                MySqlParameter[] arrParam = new MySqlParameter[1];
                arrParam[0] = new MySqlParameter("_LanguageID", id);
                dt = DataUtil.executeStore(cmdText, arrParam);
                DataRow row = dt.NewRow();
                row[0] = "-1";
                row[1] = "All";
                dt.Rows.InsertAt(row, 0);
            }
            catch (Exception ex)
            {
                return null;
            }
            return dt;
        }
        /* Author Jenny
         * Date : 10/4/2012
         * function getAllActionsVariable
         * get all actions such as Insert, update...
         * no return
         * now only use english
         */
        public void getAllActionsVariable()
        {
            try
            {
                int i = 0;
                DataTable dt = new DataTable();
                DataUtil.connect();
                String cmdText = "sp_getAllActionsVariable";
                MySqlDataReader reader = DataUtil.executeReader(cmdText, null);
                DataRow row = dt.NewRow();
                while (reader.Read())
                {
                    dt.Columns.Add(reader["ActionsVariable"].ToString());
                    row[i] = reader["ID"].ToString();
                    i++;
                }
                Constant.DR_ACTIONS_VARIABLE = row;
            }
            catch (Exception ex)
            {
            }
        }
    }
}
